﻿import QtQuick 2.0
import QtQuick.Window 2.12

Item {
//    FontLoader{
//        id: fontLoader
//        source: "qrc:/AlibabaPuHuiTi-3-55-Regular.ttf"
//    }

    // 自适应缩放
    property real dpScale: 1.2
//    property real dp_density: Math.max(Math.min(Screen.pixelDensity * 0.15 * dpScale, 1.2), 0.6)
//    property real dp_pixel: Math.min(Screen.width *0.00055, 1.2)
////    property real dp: Math.min(dp_pixel, dp_density)
//    property real dp: dp_pixel
    property real dp: 1


//    Component.onCompleted: {
//        dp = CTools.readDp()
//    }
    property real fontsize_b: fontsize * 0.7
    property real fontsize_a: fontsize * 0.88
    property real fontsize: 15.5 * dp
    property real fontsize_1: fontsize * 1.25
    property real fontsize_2: fontsize * 1.5
    property real fontsize_3: fontsize * 2

    property int device: {
        if(Qt.platform.os === "windows"){
            return 0
        }if(Qt.platform.os === "android"){
            return 1
        }if(Qt.platform.os === "linux" || Qt.platform.os === "unix"){
            return 2
        }
    }          // [0]PC [1]安卓(会禁用Hover样式)  [2]Linux
    property bool hoverEnabled:  device === 0 || device === 2

    property color themeColor: "#1677FF"
    property color themeColor_light1: lightColor(themeColor)
    property color themeColor_light2: "#F2F9FF"
    property color themeColor_deep: deepColor(themeColor)

    property color redColor: "#F56C6C"
    property color greenColor: "#67C23A"
    property color blueColor: "#2787FC"
    property color yellowColor: "#E6A23C"

    property var validChar: ["_", "A", "a", "B", "b", "C", "c", "D", "d", "E", "e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j", "K", "k", "L", "l", "M", "m", "N", "n", "O", "o", "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t", "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y", "Z", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]

    function lightColor(color){
        var weight = color.r+color.g+color.b
        let r = Math.min(255, color.r*255 + 30 + weight*30*(1-color.r))
        let g = Math.min(255, color.g*255 + 30 + weight*30*(1-color.g))
        let b = Math.min(255, color.b*255 + 30 + weight*30*(1-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }
    function lightColor2(color){
        var weight = color.r+color.g+color.b
        let r = Math.min(255, color.r*255 + 30 + weight*100*(1-color.r))
        let g = Math.min(255, color.g*255 + 30 + weight*100*(1-color.g))
        let b = Math.min(255, color.b*255 + 30 + weight*100*(1-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }

    function deepColor(color){
        let r = Math.max(0, color.r*255 - 30 * (1.2-color.r))
        let g = Math.max(0, color.g*255 - 30 * (1.2-color.g))
        let b = Math.max(0, color.b*255 - 30 * (1.2-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }
    function deepColor2(color){
        let r = Math.max(0, color.r*255 - 30 * (1.6-color.r))
        let g = Math.max(0, color.g*255 - 30 * (1.6-color.g))
        let b = Math.max(0, color.b*255 - 30 * (1.6-color.b))
        return Qt.rgba(r/255, g/255, b/255, color.a)
    }

    function getOpacityColor(color, opacity){
        let r = Math.max(0, color.r)
        let g = Math.max(0, color.g)
        let b = Math.max(0, color.b)
        return Qt.rgba(r, g, b, opacity)
    }

    function reverseStepColor(color){       // 返回黑色或者白色
        var weight = color.r + color.g + color.b
        if(weight > 2.3 || color.a * (4-weight) < 1){
            return Qt.rgba(0.1, 0.1, 0.1, 1)    // 黑色
        }else{
            return Qt.rgba(1, 1, 1, 1)          // 白色
        }
    }

    // 超时未回复等待间隔
    property real return01Timeout: 10*1000              // 响应时间ms
    property real return02Timeout_long: 600*1000        // 等待时间(长)ms
    property real return02Timeout_short: 60*1000        // 等待时间(短)ms

}
